package com.atguigu.ssyx.acl.service.impl;

import com.atguigu.ssyx.acl.mapper.AdminMapper;
import com.atguigu.ssyx.acl.service.AdminService;
import com.atguigu.ssyx.model.acl.Admin;
import com.atguigu.ssyx.vo.acl.AdminQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author 杨林
 * @create 2023-07-06 17:33 星期四
 * description:
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    /**
     * 获取用户列表
     * @param adminQueryVo
     * @param adminPage
     * @return
     */
    @Override
    public IPage<Admin> selectPage(AdminQueryVo adminQueryVo, Page<Admin> adminPage) {
        //构建查询条件
        LambdaQueryWrapper<Admin> wrapper = new LambdaQueryWrapper<>();
        String name = adminQueryVo.getName();
        if (!StringUtils.isEmpty(name)){
            wrapper.like(Admin::getName,name);
        }
        String username = adminQueryVo.getUsername();
        if (!StringUtils.isEmpty(username)){
            wrapper.like(Admin::getUsername,username);
        }
        IPage<Admin> pageModel = adminMapper.selectPage(adminPage, wrapper);
        return pageModel;
    }
}
